import { RunningService } from './../services/count';
import { Router } from '@angular/router';
import { Alarm } from './../domain/alarm';
import { AlarmService } from './../services/alarm.service';
import { LocationStrategy } from '@angular/common';
import { Component, OnInit, Directive, HostListener } from '@angular/core';

@Component({
  selector: 'ree-counts',
  templateUrl: './counts.component.html',
  styleUrls: ['./counts.component.scss'],
})
export class CountsComponent implements OnInit {
  numberOfClicks
  constructor(
    private as: AlarmService,
    private router: Router,
    private RunningService: RunningService
  ) { }


  filter = {
    deviceType: '',
    delarAccounts: '',
    customerAccounts: '',
    deviceSidOrModel: ''
  }
  alarmList: Alarm[] = [];

  selectedOption;
  searchOptions = [
    { value: '空压机', label: '空压机' },
    { value: '干燥机', label: '干燥机' },
    { value: '冷冻机', label: '冷冻机' }
  ];

  ngOnInit() {
    this.getAlarmList();
    //console.log()
  }

  getAlarmList() {
    this.as.getAlarmList()
      .then(data => {
        this.alarmList = data;
      })
  }
  onSubmit(){
    console.log(this.filter,JSON.stringify(this.filter))
  }

  public data: any[] = this.alarmList;

  public save(component): void {
    const options = component.workbookOptions();
    const rows = options.sheets[0].rows;

    let altIdx = 0;
    rows.forEach((row) => {
      if (row.type == 'data') {
        if (altIdx % 2 !== 0) {
          row.cells.forEach((cell) => {
            cell.background = "#aabbcc";
          });
        }
        altIdx++;
      }
    });

    component.save(options);
  }

  ngOnDestroy() {
    console.log("s")
    sessionStorage.setItem('filter', "s")
  }

  change() {
    this.router.navigate(['work/running/counts', { filter:JSON.stringify(this.filter)}]);
  }                                

}
